package com.couduidui.my.app.user.controller;



import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.couduidui.my.app.datasource.DynamicDataSourceRegister;
import com.couduidui.my.app.user.domain.Role;
import com.couduidui.my.app.user.domain.User;
import com.couduidui.my.app.user.service.UserService;

/** 
* @date 2017年6月19日 上午11:11:36
* @author  错对对
* @see     用户登录控制层
*/ 
@RestController
@RequestMapping(value="/api/user")
public class UserLoginController {

	 private final Logger logger = LoggerFactory.getLogger(this.getClass());  
	 
	@Autowired
	private UserService UserService;
	
	/**
	 * 获取用户列表
	 * @return
	 * @author  错对对
	 * @date    2017年6月20日
	 */
	@RequestMapping(value="/",method=RequestMethod.GET)
	public List<User> userLogin() {
		logger.debug("This is a debug message");  
        logger.info("This is an info message");  
        logger.warn("This is a warn message");  
        logger.error("This is an error message"); 
        List<String> names = Arrays.asList("peter", "anna", "mike", "xenia");
    	Collections.sort(names, new Comparator<String>() {
    	    @Override
    	    public int compare(String a, String b) {
    	        return b.compareTo(a);
    	    }
    	});
    	Collections.sort(names,(String a,String b)->b.compareTo(a));//和ts中的箭头函数相似
        return UserService.getUserList();
    }
	/**
	 * 获取角色信息
	 * @param roleId
	 * @return
	 * @author  错对对
	 * @date    2017年6月20日
	 */
	@RequestMapping(value="/getRole/{id}",method=RequestMethod.GET)
	public Role getRole(@PathVariable("id") int roleId){
		return UserService.getRole(roleId);
	}
	//usf 格式实例
//	 @RequestMapping(value = "/api/city/{id}", method = RequestMethod.GET)
//	    public City findOneCity(@PathVariable("id") Long id) {
//	        return cityService.findCityById(id);
//	    }
//
//	    @RequestMapping(value = "/api/city", method = RequestMethod.GET)
//	    public List<City> findAllCity() {
//	        return cityService.findAllCity();
//	    }
//
//	    @RequestMapping(value = "/api/city", method = RequestMethod.POST)
//	    public void createCity(@RequestBody City city) {
//	        cityService.saveCity(city);
//	    }
//
//	    @RequestMapping(value = "/api/city", method = RequestMethod.PUT)
//	    public void modifyCity(@RequestBody City city) {
//	        cityService.updateCity(city);
//	    }
//
//	    @RequestMapping(value = "/api/city/{id}", method = RequestMethod.DELETE)
//	    public void modifyCity(@PathVariable("id") Long id) {
//	        cityService.deleteCity(id);
//	    }
	
	
}
